import get_params from '@dfeidao/atom-nodejs/authorization/get-params';
import { ICommonParams, IHeaders } from '@dfeidao/atom-nodejs/interfaces';
import log from '@dfeidao/atom-nodejs/logger/log';
import whoami from '@dfeidao/atom-nodejs/msg/whoami';
import { IncomingHttpHeaders } from 'http';

interface Message {
	filter: {};
	page_size: number;
	page_no: number;
}

interface IWebResult {
	data: unknown;
	cookie?: {
		[name: string]: string;
	} | null;
	content_type?: string;
	headers?: {
		[key: string]: string[];
	};
	attachment?: string;
	redirect?: string;
	status_code?: number;
}

export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders): Promise<IWebResult> {
	log('Service begin path:atom/s001,action_id:' + action_id);
	const userinfo = await whoami(action_id, session_id);
	const msg = {
		cookie: { sessionid: session_id },
		data: {},
		headers: {},
		params: {},
		query: {},
		remote_address: '',
		spaceid: "",
		url: ""
	} as ICommonParams;
	const hearders = {
		actionid: action_id
	} as IHeaders;
	const productid = userinfo.productid;
	const params = await get_params(msg, hearders, productid, '3');
	log('Service end path:atom/s001,action_id:' + action_id);
	return { data: { userinfo, params } } as IWebResult;
}
